#include "NonUser.h"

NonUser::NonUser() {
	
}

NonUser::NonUser(Objects3D l) : nonuser(l), timePassed( dbTimer() ) 
{
}


NonUser::~NonUser() {

}

void NonUser::changeObjects(Objects3D l) {

		this->nonuser = l;
}

void NonUser::addObject(int uOb, Agent* p) {

	this->nonuser.addItem(uOb, p);

}

void NonUser::removeObject(int uOb) {

	this->nonuser.remove(uOb);	

}

int NonUser::numObjects() {

	return this->nonuser.size();

}

void 
NonUser::scanAndUpdate()
{
	int elapsedTime = dbTimer() - timePassed;
	int changeTime = 3000;
	
	list<Agent*>::iterator element;
	for(element = nonuser.objects.begin(); element != nonuser.objects.end(); element++)
	{
		// get the display object 
		Agent* obj = (Agent *) *element;

		if (obj == NULL)
			continue;

		if( elapsedTime > changeTime )
		{
			//dbPlayObject( obj->getID(), 1 );
			//obj->playAnimation( Agent::Attack );
			obj->playAnimation( (Animation::Action) obj->getState() );
		}
		

		// Move them in a kind of square
		float x = 0; 
		float z = 0;
		//if (obj->getState() == obj->Walking )
		//	x = 4.5f;
		//if (obj->getState() == obj->Idle )
		//	z = 4.5f;
		//if (obj->getState() == obj->Attacking )
		//	x = -4.5f;
		//if (obj->getState() == obj->Fleeing )
		//	z = -4.5f;

		obj->setPosition(obj->getPosX() + x, obj->getPosY(), obj->getPosZ() + z);
		obj->setState((Agent::State)(obj->getState() + 1));
		if (obj->getState() > 3)
			obj->setState(obj->Walking);
	}

	if( elapsedTime > changeTime )
		timePassed = dbTimer();

}